import { DisplayUtil } from "../../../../../common/DisplayUtil";
import { EffectManager } from "../../../../manager/EffectManager";
import { AutoGuideData } from "../AutoGuideData";
import { GuideArrowManager } from "../../../../manager/GuideArrowManager";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { GuideArrow } from "../../../guide/GuideArrow";
import { LineBox } from "../../../guide/LineBox";
type int = number;
//class AutoGuideStepBase
    
    export  class AutoGuideStepBase
    {
        constructor()
        {
            
            this._datas = new Map<any, any> /* flash.utils.Dictionary */();
            return;
        }

        protected showMask(arg1: Object /* flash.display.DisplayObjectContainer */, arg2: Object /* flash.display.DisplayObject */): void
        {
            var loc1=DisplayUtil.getRelativePlace(arg1, arg2);
            DisplayUtil.drawHollowMask(this.mask, arg2.width + 2, arg2.height + 2);
            this.mask.x = (loc1.x - 1);
            this.mask.y = (loc1.y - 1);
            arg1.addChild(this.mask);
            return;
        }

        protected showLineBox(arg1: Object /* flash.display.DisplayObjectContainer */, arg2: Object /* flash.display.DisplayObject */): void
        {
            this._lineBox = EffectManager.getLineBox(arg2.width + 4, arg2.height + 4);
            this._lineBox.x = arg2.x - 2;
            this._lineBox.y = arg2.y - 2;
            arg1.addChild(this._lineBox);
            return;
        }

        protected showArrow(arg1: Object /* flash.display.DisplayObjectContainer */, arg2: AutoGuideData, arg3: Object /* flash.display.DisplayObject */): void
        {
            flash.utils.clearTimeout(this._arrowTimerId);
            this.arrow.updateDir(arg2.arrowDirection);
            var loc1=DisplayUtil.getRelativePlace(arg1, arg3);
            var loc2=arg2.arrowDirection;
            switch (loc2) 
            {
                case GuideArrowManager.Dir_B:
                {
                    this.arrow.x = loc1.x + arg3.width / 2;
                    this.arrow.y = loc1.y - 9;
                    break;
                }
                case GuideArrowManager.Dir_L:
                {
                    this.arrow.x = loc1.x + arg3.width + 4;
                    this.arrow.y = loc1.y + arg3.height / 2;
                    break;
                }
                case GuideArrowManager.Dir_R:
                {
                    this.arrow.x = loc1.x - 4;
                    this.arrow.y = loc1.y + arg3.height / 2;
                    break;
                }
                case GuideArrowManager.Dir_T:
                {
                    this.arrow.x = loc1.x + arg3.width / 2;
                    this.arrow.y = loc1.y + arg3.height + 9;
                    break;
                }
            }
            arg1.addChild(this.arrow);
            return;
        }

        protected get mask(): Object /* flash.display.Sprite */
        {
            if (this._mask == null) 
            {
                this._mask = new Object /* flash.display.Sprite */();
                this._mask.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.maskAddToStageHandler);
            }
            return this._mask;
        }

        protected maskAddToStageHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._maskTimerId != 0) 
            {
                flash.utils.clearTimeout(this._maskTimerId);
            }
            var loc1=0;
            if (this._data != null) 
            {
                loc1 = this._data.guideTime;
            }
            if (loc1 == 0) 
            {
                loc1 = 8000;
            }
            this._maskTimerId = flash.utils.setTimeout(this.maskShowTimeOut, loc1);
            return;
        }

        protected maskShowTimeOut(): void
        {
            if (this._maskTimerId != 0) 
            {
                flash.utils.clearTimeout(this._maskTimerId);
                this._maskTimerId = 0;
            }
            DisplayUtil.removeMe(this._mask);
            if (this._data == null) 
            {
                return;
            }
            if (this._data.isBreakAfterMaskOut) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideBreakGuide, this._data));
            }
            return;
        }

        protected get arrow(): GuideArrow
        {
            if (this._arrow == null) 
            {
                this._arrow = new GuideArrow();
                this._arrow.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.arrowAddHandler);
                this._arrow.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.arrowRemovedHandler);
            }
            return this._arrow;
        }

        protected arrowAddHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=0;
            if (this._data != null) 
            {
                loc1 = this._data.guideTime;
            }
            if (loc1 == 0) 
            {
                loc1 = 8000;
            }
            flash.utils.clearTimeout(this._arrowTimerId);
            this._arrowTimerId = flash.utils.setTimeout(this.arrowTimer, loc1);
            return;
        }

        protected arrowTimer(): void
        {
            this._arrowTimerId = 0;
            if (this._updatePlaceTiemr != null) 
            {
                this._updatePlaceTiemr.stop();
            }
            DisplayUtil.removeMe(this.arrow);
            return;
        }

        protected arrowRemovedHandler(arg1: Object /* flash.events.Event */): void
        {
            flash.utils.clearTimeout(this._arrowTimerId);
            if (this._updatePlaceTiemr != null) 
            {
                this._updatePlaceTiemr.stop();
            }
            this._arrowTimerId = 0;
            return;
        }

        protected /* var */_datas: Map<any, any> /* flash.utils.Dictionary */;

        protected /* var */_mask: Object /* flash.display.Sprite */;

        protected /* var */_arrow: GuideArrow;

        protected /* var */_lineBox: LineBox;

        protected /* var */_arrowTimerId: int;

        protected /* var */_updatePlaceTiemr: Object /* flash.utils.Timer */;

        protected /* var */_data: AutoGuideData;

        protected /* var */_maskTimerId: int;
    }
